import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:hc_bot_pro/chat/index.dart';
import 'package:hc_bot_pro/chat/state.dart';
import 'package:hc_bot_pro/chat/widgets/end_button.dart';

import 'cell.dart';

class ChatListView extends StatelessWidget {
  const ChatListView({super.key});

  @override
  Widget build(BuildContext context) {
    final controller = Get.find<ChatController>();
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "AI健康管家",
            style: TextStyle(
              color: Color(0xFF3D41A0),
              fontSize: 22.sp,
              fontWeight: FontWeight.w500,
            ),
          ).paddingOnly(bottom: 15.h),
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: Color(0xFF003A7F).withOpacity(0.07),
                borderRadius: BorderRadius.circular(10.sp),
              ),
              child: ListView.separated(
                itemCount: controller.state.chatList.length,
                controller: controller.tableViewController,
                padding: EdgeInsets.only(
                  left: 12.w,
                  right: 12.w,
                  top: 15.h,
                  bottom: 15.h,
                ),
                separatorBuilder: (BuildContext context, int index) {
                  return Container(height: 15.h);
                },
                itemBuilder: (BuildContext context, int index) {
                  final item = controller.state.chatList[index];
                  return Cell(model: item);
                },
              ),
            ),
          ),
          EndButton().paddingOnly(top: 10.h),
        ],
      ),
    );
  }
}
